package com.xiongwei.status;

import java.util.Random;

/**
 * 可以抽奖状态
 * @author XiongWei
 * @date 2024/2/19
 */
public class RaffleState implements State{

    private RaffleActivity raffleActivity;

    public RaffleState(RaffleActivity raffleActivity) {
        this.raffleActivity = raffleActivity;
    }

    @Override
    public void deductPoint() {
        System.out.println("已经扣除过积分了");
    }

    @Override
    public Boolean raffle() {
        System.out.println("开始抽奖");
        Random r = new Random();
        int i = r.nextInt(10);
        //中奖概率为50%
        if (i < 5) {
            System.out.println("恭喜你，中奖啦！");
            //状态修改为发放奖品状态
            raffleActivity.setState(raffleActivity.getDispensePrizeState());
            return true;
        } else {
            System.out.println("很抱歉，未中奖");
            //状态修改为不能抽奖状态
            raffleActivity.setState(raffleActivity.getNoRaffleState());
            return false;
        }
    }

    @Override
    public void dispensePrize() {
        System.out.println("不能发放奖品");
    }
}
